#include "CWindow.h"
#include <string.h>


CWindow::CWindow()
{
	this->hWindow = NULL;
}

CWindow::~CWindow()
{
	if(this->hWindow)
		delete this->hWindow;
}

int CWindow::Create(HINSTANCE hInstance, std::string title, int x, int y, int width, int height)
{
	if(this->getHWND() != NULL)
		return 0;
	
	std::string g_strKlasaOkna = "GrafikaProject1_Class";
	//Wypelnienie struktury WNDCLASSEX
	ZeroMemory(&this->windowClass, sizeof(WNDCLASSEX));
	this->windowClass.cbSize = sizeof(WNDCLASSEX);
	this->windowClass.hInstance = hInstance;
	this->windowClass.lpfnWndProc = CWindowEventProc;
	this->windowClass.lpszClassName = (LPCSTR)g_strKlasaOkna.c_str();
	this->windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	this->windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	this->windowClass.hbrBackground = (HBRUSH) COLOR_WINDOW;
	//WS_EX_TOPMOST | WS_POPUP

	// rejestracja klasy okna
	RegisterClassEx(&this->windowClass);
	this->hWindow = CreateWindowEx(NULL,
							(LPCSTR)g_strKlasaOkna.c_str(),
							(LPCSTR)title.c_str(),
							//WS_EX_TOPMOST | WS_POPUP, 
							WS_OVERLAPPEDWINDOW ,
							x, y,
							width, height,
							NULL,
							NULL,
							hInstance,
							NULL);
	return 1;
}

HWND CWindow::getHWND()
{
	return this->hWindow;
}

void CWindow::Show()
{
	ShowWindow(hWindow,1);
	
}


LRESULT CALLBACK CWindowEventProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
	}
	return DefWindowProc(hWindow, uMsg, wParam, lParam);
}